package tcp

import (
	"encoding/json"
	"fmt"
	"go.uber.org/zap"
	"net"
	"os_client/logger"
	"os_client/models"
	"os_client/zero_os"
	"time"
)

var ConfigModel models.ConfigModel
var Z = make(map[string]interface{})

func InitClent() {
	url := ConfigModel.MasterUrl
	conn, err := net.Dial("tcp", url)
	if err != nil {
		fmt.Println("error is:", err)
	}
	defer conn.Close()
	for {
		Z["getCpu"] = zero_os.GetCpu
		Z["getMem"] = zero_os.GetMem
		Z["getNetSent"] = zero_os.SentNum
		Z["getNetRecv"] = zero_os.RecvNum
		Z["DeskInfo"] = zero_os.DeskInfo
		file, err := json.Marshal(Z)
		logger.Logger.Info("发送内容", zap.Any("clent", Z))
		_, err = conn.Write(file)
		if err != nil {
			fmt.Println("写入数据错误：", err)
			break
		}
		time.Sleep(time.Second)
	}
}
